<?php

use think\migration\Migrator;
use think\migration\db\Column;

class CreateAdminTable extends Migrator
{
    /**
     * Change Method.
     *
     * Write your reversible migrations using this method.
     *
     * More information on writing migrations is available here:
     * http://docs.phinx.org/en/latest/migrations.html#the-abstractmigration-class
     *
     * The following commands can be used in this method and Phinx will
     * automatically reverse them when rolling back:
     *
     *    createTable
     *    renameTable
     *    addColumn
     *    renameColumn
     *    addIndex
     *    addForeignKey
     *
     * Remember to call "create()" or "update()" and NOT "save()" when working
     * with the Table class.
     */
    public function change()
    {
        $this->table('admin', ['comment'=>'管理员账号'])
            ->addColumn(Column::string('username', 100)->setComment('用户名'))
            ->addColumn(Column::string('nickname', 100)->setNullable()->setComment('呢称'))
            ->addColumn(Column::string('password', 100)->setNullable()->setComment('密码'))
            ->addColumn(Column::string('telephone', 20)->setNullable()->setComment('手机号'))
            ->addColumn(Column::string('email', 100)->setNullable()->setComment('邮箱'))
            ->addColumn(Column::tinyInteger('status')->setDefault(1)->setComment('状态，1正常，0禁用'))
            ->addColumn(Column::json('authority')->setNullable()->setComment('访问权限'))
            ->addColumn(Column::string('ip', 40)->setDefault('')->setNullable()->setComment('用户ip'))

            ->addColumn(Column::integer('login_time')->setNullable()->setComment('登陆时间'))
            ->addColumn(Column::integer('create_time')->setComment('创建时间'))
            ->addColumn(Column::integer('update_time')->setComment('修改时间')->setNullable())
            ->addColumn(Column::integer('delete_time')->setComment('删除时间')->setNullable())
            ->create();
    }
}
